Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[google_maps_flutter] Take snapshot of map #2607

Merged
merged 15 commits into from
Mar 24, 2020
Merged

[google_maps_flutter] Take snapshot of map #2607

merged 15 commits into from
Mar 24, 2020

Conversation

miyakeryo
Copy link
Contributor

@miyakeryo miyakeryo commented Mar 14, 2020

Description

Added function for taking a snapshot of the map

Related Issues

#1719
flutter/flutter#33557

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@miyakeryo
Copy link
Contributor Author

@googlebot I signed it! and we'll verify it.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@miyakeryo miyakeryo changed the title [google_maps_flutter] Take screenshot of map [google_maps_flutter] Take snapshot of map Mar 14, 2020
Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I left some comments!


final GoogleMapInspector inspector = await inspectorCompleter.future;
final Uint8List bytes = await inspector.takeSnapshot();
expect(bytes, isNotNull);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can probably remove this as if bytes is null, the below test would fail as well.

@cyanglaz cyanglaz added the submit queue The Flutter team is in the process of landing this PR. label Mar 18, 2020
@cyanglaz cyanglaz self-assigned this Mar 18, 2020
Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo nits. Thanks!

AUTHORS Outdated
Giancarlo Rocha <giancarloiff@gmail.com>
Ryo Miyake <ryo@miyake.id>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add new line EOF here?

@@ -1,3 +1,7 @@
## 0.5.25+1

* Added function for taking a snapshot of the map.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits: Add takeSnapshot that takes a snapshot of the map.

@@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:typed_data';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits: remove extra line here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's required to use Uint8List.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh! extra line. ok

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@cyanglaz cyanglaz merged commit 03182d2 into flutter:master Mar 24, 2020
@miyakeryo
Copy link
Contributor Author

thanks!

@fvisticot
Copy link

I need to take the snapshot once the map widget has been renderer:

using WidgetsBinding.instance.addPostFrameCallback

_onAfterBuild(BuildContext context) async {
    if (_image == null) {
      final GoogleMapController controller = await _completer.future;
      final bytes = await controller?.takeSnapshot();
      _image = Image.memory(bytes);
    }
  }

I get a crash on iOS (stable version)


Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Data cannot be nil'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff23c7127e __exceptionPreprocess + 350
	1   libobjc.A.dylib                     0x00007fff513fbb20 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff23c70ff8 +[NSException raise:format:arguments:] + 88
	3   Foundation                          0x00007fff256e9b51 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
	4   Flutter                             0x000000010381ae08 -[FlutterStandardTypedData initWithData:type:] + 335
	5   Flutter                             0x000000010381aca0 +[FlutterStandardTypedData typedDataWithData:type:] + 59
	6   Runner                              0x0000000102bdfd28 -[FLTGoogleMapController onMethodCall:result:] + 4584
	7   Runner                              0x0000000102bdeae1 __75-[FLTGoogleMapController initWithFrame:viewIdentifier:arguments:registrar:]_block_invoke + 161
	8   Flutter                             0x0000000103818b35 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 104
	9   Flutter                             0x00000001037ac920 _ZNK7flutter21PlatformMessageRouter21HandlePlatformMessageEN3fml6RefPtrINS_15PlatformMessageEEE + 166
	10  Flutter                             0x00000001037b03ce _ZN7flutter15PlatformViewIOS21HandlePlatformMessageEN3fml6RefPtrINS_15PlatformMessageEEE + 38
	11  Flutter                             0x00000001038126e9 _ZNSt3__110__function6__funcIZN7flutter5Shell29OnEngineHandlePlatformMessageEN3fml6RefPtrINS2_15PlatformMessageEEEE4$_32NS_9allocatorIS8_EEFvvEEclEv + 57
	12  Flutter                             0x00000001037bf8f3 _ZN3fml15MessageLoopImpl10FlushTasksENS_9FlushTypeE + 117
	13  Flutter                             0x00000001037c4638 _ZN3fml17MessageLoopDarwin11OnTimerFireEP16__CFRunLoopTimerPS0_ + 26
	14  CoreFoundation                      0x00007fff23bd4b94 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
	15  CoreFoundation                      0x00007fff23bd4882 __CFRunLoopDoTimer + 1026
	16  CoreFoundation                      0x00007fff23bd3eda __CFRunLoopDoTimers + 266
	17  CoreFoundation                      0x00007fff23bcec4e __CFRunLoopRun + 2238
	18  CoreFoundation                      0x00007fff23bce066 CFRunLoopRunSpecific + 438
	19  GraphicsServices                    0x00007fff384c0bb0 GSEventRunModal + 65
	20  UIKitCore                           0x00007fff48092d4d UIApplicationMain + 1621
	21  Runner                              0x00000001026cbc2b main + 75
	22  libdyld.dylib                       0x00007fff5227ec25 start + 1
	23  ???                                 0x0000000000000001 0x0 + 1

@cyanglaz
Copy link
Contributor

@fvisticot Thanks for finding this out. Do you mind open an issue with details about this crash and tag me there?
In your issue, it would be super helpful if you can provide a reduced test case. It will help us to reproduce the issue quickly and get resolved quickly.

@greensopinion
Copy link

I get a crash on iOS (stable version)

I've filed an issue with reproduction steps: flutter/flutter#81690

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes submit queue The Flutter team is in the process of landing this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants